package com.dateme.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.dateme.R;

public class HereForDialog extends Dialog implements OnItemClickListener {

	Context mContext;
	ListView listHerefor;
	EditText etHereFor;

	public HereForDialog(Context context, EditText etHereFor) {
		// TODO Auto-generated constructor stub
		super(context);
		mContext = context;
		this.etHereFor = etHereFor;
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		Window window = getWindow();
		window.setBackgroundDrawableResource(android.R.color.transparent);
		window.requestFeature(window.FEATURE_NO_TITLE);
		setContentView(R.layout.registration_herefordialog);
		listHerefor = (ListView) findViewById(R.id.listHerefor);
		listHerefor.setOnItemClickListener(this);
		String[] values = mContext.getResources().getStringArray(
				R.array.herefor_array);
		Integer[] imageName = new Integer[] { R.drawable.iht_bubble_friends,
				R.drawable.iht_bubble_chat, R.drawable.iht_bubble_date };
		listHerefor.setAdapter(new MySimpleArrayAdapter(mContext, values,
				imageName));
	}

	public class MySimpleArrayAdapter extends ArrayAdapter<String> {
		private final Context context;
		private final String[] values;
		private final Integer[] imageName;

		public MySimpleArrayAdapter(Context context, String[] values,
				Integer[] imageName) {
			super(context, R.layout.raw_listherefor, values);
			this.context = context;
			this.imageName = imageName;
			this.values = values;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			LayoutInflater inflater = (LayoutInflater) context
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			View rowView = inflater.inflate(R.layout.raw_listherefor, parent,
					false);
			TextView textView = (TextView) rowView
					.findViewById(R.id.tv_herefor);
			ImageView imageView = (ImageView) rowView
					.findViewById(R.id.img_herefor);
			textView.setText(values[position]);
			// change the icon for Windows and iPhone

			imageView.setImageResource(imageName[position]);

			return rowView;
		}
	}

	@Override
	public void onItemClick(AdapterView<?> adapterView, View view,
			int position, long id) {
		// TODO Auto-generated method stub
		etHereFor
				.setText(adapterView.getAdapter().getItem(position).toString());
		dismiss();
	}
}
